package com.sxzbxc.weixin.service.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sxzbxc.weixin.dao.InfoMelfunctionDao;
import com.sxzbxc.weixin.entity.infoMelfunction;
import com.sxzbxc.weixin.service.InfoMelfunctionServiceI;

@Service("infoMelfunctionServiceImpl")
public class InfoMelfunctionServiceImpl implements InfoMelfunctionServiceI {

	@Autowired
	private InfoMelfunctionDao infoMelfunctionDao;
	
	@Override
	public List<infoMelfunction> loadAll() {
		List<infoMelfunction> loadAll = infoMelfunctionDao.loadAll();
		return loadAll;
	}

	@Override
	public void insertSelective(infoMelfunction entity) {
		infoMelfunctionDao.insertSelective(entity);
		
	}

	@Override
	public infoMelfunction selectByPrimaryKey(String id) {
		infoMelfunction selectByPrimaryKey = infoMelfunctionDao.selectByPrimaryKey(id);
		return selectByPrimaryKey;
	}

	@Override
	public void updateByPrimaryKeySelective(infoMelfunction record) {
		infoMelfunctionDao.updateByPrimaryKeySelective(record);
		
	}

	@Override
	public List<infoMelfunction> selectByDate(Integer id) {
		List<infoMelfunction> selectByDate = null ;
		//SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Calendar c = Calendar.getInstance();
        Date date = new Date();
    	c.set(Calendar.HOUR_OF_DAY, 24);
    	c.set(Calendar.SECOND, 0);
    	c.set(Calendar.MINUTE, 0);
    	c.set(Calendar.MILLISECOND, 0);
    	date = c.getTime();
        Date m = new Date();
        if(id==1){
        //过去一周
	        c.setTime(new Date());
	        c.add(Calendar.WEEK_OF_MONTH, -1);
	        m = c.getTime();
	        //String mon = format.format(m);
        }else if(id==2){
        	//过去一月
        	c.setTime(new Date());
            c.add(Calendar.MONTH, -1);
            m = c.getTime();
        }else if(id == 3){
        	//过去一季度
        	c.setTime(new Date());
        	c.add(Calendar.MONTH, -3);
        	m = c.getTime();
        }else if(id ==4){
        	//过去一年
        	c.setTime(new Date());
        	c.add(Calendar.YEAR, -1);
        	m = c.getTime();
        }else if(id ==0){
        	Calendar c1 = Calendar.getInstance();
        	c1.set(Calendar.HOUR_OF_DAY, 0);
        	c1.set(Calendar.SECOND, 0);
        	c1.set(Calendar.MINUTE, 0);
        	c1.set(Calendar.MILLISECOND, 0);
        	m = c1.getTime();
        }
        try {
        	Map<String , Date> map = new HashMap<String, Date>();
            map.put("eDate", date);//结束时间
            map.put("bDate", m);//开始时间
            selectByDate = infoMelfunctionDao.selectByDate(map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return selectByDate;
	}

	@Override
	public infoMelfunction selectByWordOrder(String wordOrder) {
		infoMelfunction entity = infoMelfunctionDao.selectByWordOrder(wordOrder);
		if(entity!=null){
			return entity;
		}
		return null;
	}

	@Override
	public List<infoMelfunction> selectByMelType(String infoMelfunctionType) {
		List<infoMelfunction> selectByMelType = infoMelfunctionDao.selectByMelType(infoMelfunctionType);
		return selectByMelType;
	}

	@Override
	public void deleteByPrimaryKey(String id) {
		infoMelfunctionDao.deleteByPrimaryKey(id);
	}

	
}
